package com.wswy.wzcx.ui.coupon

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import com.wswy.wzcx.api.Api
import com.wswy.wzcx.model.UserMode
import com.wswy.wzcx.model.coupon.CouponResp
import com.wswy.wzcx.module.base.BaseViewModel
import com.wswy.wzcx.module.base.Resource
import com.wswy.wzcx.module.base.UserViewModel
import com.wswy.wzcx.module.base.onResult

class CouponViewModel : UserViewModel() {

    private val couponRespLiveData = MutableLiveData<Resource<CouponResp?>>()

    var selectedId = -1L

    fun load(){


        addRun(Api.get().couponList().onResult(couponRespLiveData))

//        addRun(Api.get().couponList().onResult({
//
//
//            couponRespLiveData.postValue(Resource.success(CouponResp(null,it?.list)))
//
//        },{
//
//        }))

    }

    override fun onUserLoginSuccess(userMode: UserMode?) {
        super.onUserLoginSuccess(userMode)
        load()
    }

    fun getCouponRespLiveData() : LiveData<Resource<CouponResp?>> = couponRespLiveData

}